<template>
  <div class="mvBox">
    <div class="MvItem" v-for="(item, index) in videoList" :key="index">
      <div class="videoBox" v-if="item.id===playId">
        <video ref="video" class="video" autoplay :poster="item.imgurl16v9" :src="currentVidioSrc+'?param=750y360'" controls="controls"></video>
      </div>
      <!-- 视频图片 -->
      <div class="vedioImg" @click="toPlay(item.id)" v-else>
        <div class="zhez"></div>
        <div class="img">
          <img  v-lazy="item.imgurl16v9+'?param=750y360'" alt="" />
          </div>
        <div class="play">
          <i class="iconfont icon-yunhang"></i>
        </div>
        <div class="mvDetail">
          <div class="left">
            <div class="a1">▷ {{ item.playCount }}</div>
          </div>
          <div class="right">
            <div class="a2">{{ item.duration }}</div>
          </div>
        </div>
      </div>
      <div class="bottom2">
        {{ item.name }}
      </div>
      <div class="detail">
        <div class="bbox">
          <div class="bleft">
            <img class="img" v-lazy="item.avatarUrl+'?param=80y80'" alt="" />
            <div class="bname">{{ item.nickname }}</div>
          </div>
          <div class="bcenter">
            <div class="detailbox">
              <i class="iconfont icon-zan"></i>
              <span>{{ item.praisedCount }}</span>
            </div>
          </div>
          <div class="bright">
            <div class="detailbox">
              <i class="iconfont icon-liaotian"></i>
              <span>{{ item.commentCount }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script  type='module'>
export default {
  props: {
    videoList: {
      type: Array,
      default: () => []
    }
  },
  name: 'MvItem',
  methods: {
    // 点击播放视频
    toPlay (id) {
      this.playId = id
      // 调用获取视频地址
      this.getVideSrc(id)
      // console.log(id)
    },
    // 获取视频地址
    async getVideSrc (id) {
      const res = await this.$http.get(`/video/url?id=${id}`)
      this.currentVidioSrc = res.urls[0].url
    }
  },
  data () {
    return {
      playId: '', // 视频id
      currentVidioSrc: ''// 视频地址
    }
  },
  mounted () {
    this.video = this.$refs.video
  }
}
</script>
<style scoped lang="less">
.mvBox {
  padding: 15px 15px 0;
  box-sizing: border-box;
  .MvItem {
    width: 100%;
    border-bottom: 0.213049rem solid var(--fgx);
    .videoBox {
      width: 100%;
      // height: 300px;
      .video {
        width: 100%;
        border-radius: 8px;
      }
    }
    .detailbox {
      display: flex;
      align-items: center;
      font-size: 0.32rem;
      .iconfont {
        margin-right: 0.106667rem;
      }
    }
    .vedioImg {
      z-index: 1;
      width: 100%;
      height: 4.793609rem;
      border-radius: 8px;
      overflow: hidden;
      position: relative;
      display: flex;
      align-items: center;
      .zhez {
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        position: relative;
        z-index: 10;
      }
      .img {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
      }
      .play {
        position: absolute;
        left: 50%;
        z-index: 11;
        transform: translate(-50%);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 50px;
        .icon-yunhang {
          font-size: 1.066667rem;
          color: rgba(255, 255, 255, 0.829);
        }
      }
    }
    .img img {
      width: 100%;
      height: 100%;
    }
    .mvDetail {
      position: absolute;
      z-index: 11;
      width: 100%;
      bottom: 0;
      height: 0.639148rem;
      line-height: 0.639148rem;
      display: flex;
      color: #fff;
      font-size: 0.346205rem;
      .left {
        flex: 1;
        .a1 {
          margin-left: 0.266312rem;
        }
      }
      .right {
        flex: 1;
        float: right;
        position: relative;
        .a2 {
          position: absolute;
          right: 0.266312rem;
        }
      }
    }
    .bottom {
      width: 100%;
      margin: 0.213049rem 0;
      display: flex;
    }
    .name {
      width: 5.326232rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      flex: 6;
      font-size: 0.399467rem;
    }
    .bottom2 {
      width: 100%;
      padding: 0.266312rem 0;
      line-height: 0.453333rem;
      font-size: 0.399467rem;
      word-break: break-all;
      text-overflow: ellipsis;
      display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
      -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
      -webkit-line-clamp: 3; /** 显示的行数 **/
      overflow: hidden; /** 隐藏超出的内容 **/
      border-bottom: 1px solid #e9e8e8;
    }
    .detail {
      width: 100%;
      height: 1.198402rem;
      display: flex;
      align-items: center;
      .bbox {
        width: 100%;
        height: 0.798935rem;
        display: flex;
        .bleft {
          flex: 5.8;
          line-height: 0.798935rem;
          font-size: 0.372836rem;
          width: 4.953395rem;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          .img {
            width: 0.798935rem;
            height: 0.798935rem;
            border-radius: 50%;
            float: left;
            margin-right: 0.133156rem;
          }
        }
        .bcenter {
          width: 1.917443rem;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          line-height: 0.798935rem;
          font-size: 0.346205rem;
          flex: 2.1;
          img {
            margin-top: 0.146471rem;
            float: left;
            margin-right: 0.079893rem;
          }
        }
        .bright {
          width: 1.917443rem;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          line-height: 0.798935rem;
          font-size: 0.346205rem;
          flex: 2.1;
          img {
            margin-top: 0.159787rem;
            float: left;
            margin-right: 0.079893rem;
          }
        }
      }
    }
  }
}
</style>
